﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARA.Domain.Datas
{
    /// <summary>
    /// 一天的记录
    /// </summary>
    public class DayRecord
    {
        public List<JoinSegment> Segments { get; private set; }

        /// <summary>
        /// 加入时间
        /// </summary>
        public DateTime? JoinTime { get; set; }

        /// <summary>
        /// 离开时间
        /// </summary>
        public DateTime? LeaveTime { get; set; }

        public DayRecord(int year, int month, int day)
        {
            this.Year = year;
            this.Month = month;
            this.Day = day;
            Segments = new List<JoinSegment>();
        }

        public int Year { get; private set; }
        public int Month { get; private set; }
        public int Day { get; private set; }

        /// <summary>
        /// 是否是分解时间
        /// </summary>
        /// <param name="isBoundary"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        public void AddSegment(bool isBoundary, DateTime beginTime, DateTime endTime)
        {
            if(JoinTime == null)
            {
                JoinTime = beginTime;
            }
            else if(JoinTime > beginTime)
            {
                JoinTime = beginTime;
            }

            if(LeaveTime == null)
            {
                LeaveTime = endTime;
            }
            else if(LeaveTime < endTime)
            {
                LeaveTime = endTime;
            }
        }

        public bool IsEarlier()
        {
            if(LeaveTime < new DateTime(LeaveTime.Value.Year,
                LeaveTime.Value.Month,
                LeaveTime.Value.Day, 16, 20, 0))
            {
                return true;
            }
            return false;
        }

        public bool IsLate()
        {
            if (JoinTime > new DateTime(JoinTime.Value.Year,
                JoinTime.Value.Month,
                JoinTime.Value.Day, 8, 40, 0))
            {
                return true;
            }
            return false;
        }
    }
}
